package com.zjw.project.weixin.api.message;

import com.zjw.project.weixin.api.accessToken.AccessTokenRedis;
import com.zjw.project.weixin.api.message.bean.Message;
import com.zjw.project.weixin.api.message.bean.MessageText;
import com.zjw.project.weixin.util.WeixinUtil;
import lombok.extern.slf4j.Slf4j;
import net.sf.json.JSONObject;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Component;


@Slf4j
@Component
public class MessageCustomUtil {


    /**
     *
     * 客服接口-发消息
     * 接口调用请求说明
     *
     * http请求方式: POST https://api.weixin.qq.com/cgi-bin/message/custom/send?access_token=ACCESS_TOKEN
     *
     *
     */
    @Autowired
    private AccessTokenRedis accessTokenRedis;

    private static String WEIXIN_MESSAGE_CUSTOM_SEND_POST_URL = "https://api.weixin.qq.com/cgi-bin/message/custom/send?access_token=ACCESS_TOKEN";

    public void sendMessageTextLogin(String openid){
        String url = WEIXIN_MESSAGE_CUSTOM_SEND_POST_URL.replace("ACCESS_TOKEN",accessTokenRedis.getAccessTokenVal());
        Message message = new Message();
        message.setTouser(openid);
        message.setMsgtype("text");
        MessageText text = new MessageText();
        text.setContent("登录成功，您可以在平台自由的使用平台的功能完成业务开发。");
        message.setText(text);

        JSONObject jsonObject = JSONObject.fromObject(message);

        JSONObject jsonObject1 = WeixinUtil.httpRequest(url, "POST", jsonObject.toString());

        log.info("登录成功之后发送消息成功----》"+jsonObject1.toString());

    }
}
